package com.keyue.controller;

import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.domain.vo.admin.DictionaryQueryVO;
import com.keyue.domain.vo.admin.DictionaryVO;
import com.keyue.log.Log;
import com.keyue.service.admin.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author xms
 */
@RestController
@Api(tags = "系统：字典管理")
@RequestMapping("/keyue/admin/dictionary")
public class DictionaryController {

    @Resource
    private DictionaryService dictionaryService;


    @Log("查询字典列表")
    @ApiOperation("查询字典列表")
    @PostMapping(value = "/list_by_page")
    @AnonymousAccess
    public ServerResult listByPage(@RequestBody @Validated DictionaryQueryVO queryVO) {
        return dictionaryService.listByPage(queryVO);
    }

    @Log("获取所有字典")
    @ApiOperation("获取所有字典")
    @PostMapping(value = "/get_all")
    @AnonymousAccess
    public ServerResult getAll(@RequestBody @Validated DictionaryQueryVO queryVO) {
        return dictionaryService.getAll(queryVO);
    }

    @Log("新增字典")
    @ApiOperation("新增字典")
    @PostMapping("/add")
    @AnonymousAccess
    public ServerResult add(@RequestBody @Validated DictionaryVO dictionaryVO) {
        return dictionaryService.add(dictionaryVO);
    }

    @Log("修改字典")
    @ApiOperation("修改字典")
    @PostMapping("/edit")
    @AnonymousAccess
    public ServerResult edit(@RequestBody @Validated DictionaryVO dictionaryVO) {
        return dictionaryService.edit(dictionaryVO);
    }

    @Log("删除字典")
    @ApiOperation("删除字典")
    @PostMapping("/delete")
    @AnonymousAccess
    public ServerResult delete(@RequestBody @Validated DictionaryQueryVO queryVO) {
        return dictionaryService.deleteById(queryVO);
    }

}